package com.social.controller;

import com.social.pojo.Complaint;
import com.social.pojo.Result;
import com.social.pojo.vto.ComplaintVTO;
import com.social.service.ComplaintService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import static com.social.constant.MessageConstant.DATA_VALID_FAIL;

/**
 * @Author: XiaoXu
 * @Description:
 * @Date: Created in 13:20 2022/9/29
 * @Modified By:
 * @Version: 1.0
 */
@Api(tags = "ComplaintController")
@RestController
@RequestMapping("/complaint")
public class ComplaintController {

    @Resource
    private ComplaintService complaintService;

    @ApiOperation("根据id查询投诉")
    @GetMapping("/id")
    public Result getComplaintById(@RequestParam Long id){
        /**
            * @Author XiaoXu
            * @Date 2022/10/3
            * @Param [id]
            * @Return Result
            * @Description 通过id查找投诉信息
         */
        return complaintService.getComplaintById(id);
    }

    @ApiOperation("根据用户id查询提交的投诉")
    @GetMapping("/user")
    public Result getComplaintByUserId(){
        /**
            * @Author XiaoXu
            * @Date 2022/10/3
            * @Param []
            * @Return Result
            * @Description 查询当前用户的投诉信息
         */
        return complaintService.getComplaintByUserId();
    }

    @ApiOperation("根据投诉类型，时间段，投诉目标查询投诉")
    @PostMapping("/condition")
    public Result getComplaintByCondition(@RequestBody ComplaintVTO complaintVTO){
        /**
            * @Author XiaoXu
            * @Date 2022/10/4
            * @Param [category, object, begin, end]
            * @Return Result
            * @Description 多条件进行查询
         */
        return complaintService.getComplaintByCondition(complaintVTO);
    }

    @ApiOperation("查询所有投诉")
    @GetMapping("/list")
    public Result getComplainList(@RequestParam Integer pageSize ,@RequestParam Integer pageIndex){
        /**
            * @Author XiaoXu
            * @Date 2022/10/3
            * @Param [null]
            * @Return Result
            * @Description 查找所有投诉信息
         */
        return complaintService.getComplainList(pageSize , pageIndex);
    }

    @ApiOperation("保存投诉")
    @PostMapping
    public Result insert(@Validated(Complaint.ValidationGroup1.class) @RequestBody Complaint complaint ){
        /**
            * @Author XiaoXu
            * @Date 2022/10/3
            * @Param [complaint]
            * @Return Result
            * @Description 保持投诉信息
         */

        return complaintService.insert(complaint);
    }

    @ApiOperation("更新投诉信息")
    @PutMapping
    public Result updateComplaint(@Valid @RequestParam Complaint complaint){
        /**
            * @Author XiaoXu
            * @Date 2022/10/3
            * @Param [complaint]
            * @Return Result
            * @Description 更新投诉信息
         */

        return complaintService.updateComplaint(complaint);
    }

    @GetMapping("/deal")
    public Result dealComplaint(@RequestParam Long id){
        return complaintService.dealComplaint(id);
    }
}
